//判断不为空
export function isNotEmpty(value) {
    return value !== undefined && value !== null && value !== "undefined" && value !== "null" && value !== "";
}
// 时间格式化
export function DateFormat(time, cFormat) {
    if (isNotEmpty(time) && time.length < 10) {
        return time;
    }
    if (typeof time == "string") {
        time = time.replace(/-/g, "/").replace(/T/g, " ");
    }
    if (arguments.length === 0) {
        return null;
    }
    if (time == undefined || time == null || time == "") {
        return null;
    }
    let format = cFormat || "{y}/{m}/{d} {h}:{i}:{s}";
    let date = null;
    if (typeof time === "object") {
        date = time;
    } else {
        if (("" + time).length === 10 && !isNaN(Number(time))) {
            time = parseInt(time) * 1000;
        }
        date = new Date(time);
    }
    let formatObj = {
        y: date.getFullYear(),
        m: date.getMonth() + 1,
        d: date.getDate(),
        h: date.getHours(),
        i: date.getMinutes(),
        s: date.getSeconds(),
        a: date.getDay(),
    };

    let time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, function (result, key) {
        let value = formatObj[key];
        if (key === "a") return ["一", "二", "三", "四", "五", "六", "日"][value - 1];
        if (result.length > 0 && value < 10) {
            value = "0" + value;
        }
        return value || 0;
    });
    return time_str;
}


export function addCommaToNumber(num) {
    return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}